import { View, ScrollView } from '@tarojs/components';
import { useDidShow } from '@tarojs/runtime';
import { usePageTitle } from "/@/utils/hooks";
import Taro from '@tarojs/taro';
import { get } from "../../utils/request";
import {useState} from 'react'


import { AtList, AtListItem } from "taro-ui"
import "taro-ui/dist/style/components/list.scss";
import "taro-ui/dist/style/components/icon.scss"
import {NavBar, navBarHeight} from "../../components/Nav";
import {TabBar, TabBarHeight} from "../../components/tabbar";


const List = [
  {
    title: '打开卡包',
    order: 'openCard'
  },
  {
    title: '打开摄像头',
    order: 'camera'
  },
  {
    title: '扫描二维码',
    order: 'camera-qrcode'
  },
  {
    title: '超长数据列表',
    order: 'long-list-view'
  }
]

const handler = (tag) => {
  if (tag.indexOf('camera')) {
    Taro.chooseImage({
      count: 1, // 默认9
      sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
      sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有，在H5浏览器端支持使用 `user` 和 `environment`分别指定为前后摄像头
      success: function (res) {
        // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
        console.log(res.tempFilePaths);
      }
    })
  }
}

function HomePage() {
  usePageTitle('首页');
  useDidShow(async ()=>{
    await get('/test/test')
  })
  return (
    <View style={{marginTop: navBarHeight}}>
      <NavBar text="123"></NavBar>
      <AtList>
        {List.map((e,i)=>{
          return <AtListItem title={e.title} onClick={()=>handler(e.title)} arrow="right" key={i}></AtListItem>
        })}
      </AtList>
      <TabBar title='首页' />
    </View>
  )
}
export default HomePage;
